package tp.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateTool {

	public static final String TIME_FORMAT = "HH:mm";

	public static String printDate(Date date, String dateFormat) {
		DateFormat df = new SimpleDateFormat(dateFormat);
		return df.format(date);
	}

	public static String printDuree(int duree) {
		int nbHeures = duree / 60;
		int nbMin = duree % 60;

		return nbHeures + " heures et " + nbMin + " minutes";
	}

	public static void main(String[] args) {
		// Date d = createTime(23, 45);
		// System.out.println(printDate(d, TIME_FORMAT));
		// System.out.println(printHumanTime(d));

		double distance = 343;
		double vitesse = 67;

		System.out.println((int) (60 * distance / vitesse));
		System.out.println((int) (distance / vitesse));

		System.out.println(distance / vitesse);
		System.out.println(printDuree((int) (60 * distance / vitesse)));
	}

	public static Date ajouterJour(Date d, int nbJour) {
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		c.add(Calendar.DAY_OF_MONTH, nbJour);

		return c.getTime();
	}

	public static Date paseDate(String date, String format) {
		DateFormat df = new SimpleDateFormat(format);
		try {
			return df.parse(date);
		} catch (ParseException e) {
			return null;
		}
	}
}
